program mean_turn_xsret_annc
      dimension turn(21),aret(21)
!      open(unit=10,file='e:\FIS_duration\ret_turn_by_anndate.txt')
!      open(unit=99,file='e:\FIS_duration\ret_turn_before_after_annc.txt')
      open(unit=10,file='e:\FIS_duration\ret_turn_by_anndate_rep.txt')
      open(unit=99,file='e:\FIS_duration\ret_turn_before_after_annc_rep.txt')
      
1         read(10,1000,end=900)nep,ntype,jdate,(turn(nn),nn=1,21),(aret(nn),nn=1,21)
1000      format(1x,i4,1x,i1,1x,i8,21(1x,f8.5),21(1x,f9.6))
          ctb=0.
          cta=0.
          cxsb=0.
          cxsa=0.
          turnb=0.
          turna=0.
          axsb=0.
          axsa=0.
          do 10 n=1,9
              if(turn(n).ge.0.) ctb=ctb+1
              if(turn(n).ge.0.) turnb=turnb+turn(n)
              if(aret(n).ge.-1.) cxsb=cxsb+1
              if(aret(n).ge.-1.) axsb=axsb+aret(n)
10    continue              
          do 20 n=13,21
              if(turn(n).ge.0.) cta=cta+1
              if(turn(n).ge.0.) turna=turna+turn(n)
              if(aret(n).ge.-1.) cxsa=cxsa+1
              if(aret(n).ge.-1.) axsa=axsa+aret(n)
20        continue 
          if(ctb.lt.1.or.cta.lt.1) go to 1
          if(cxsa.lt.1.or.cxsb.lt.1.) go to 1
          turnb=turnb/ctb
          turna=turna/cta
          axsb=axsb/cxsb
          axsa=axsa/cxsa
          write(99,9900)nep,ntype,turnb,turna,axsb,axsa
          write(6,9900)nep,ntype,turnb,turna,axsb,axsa
9900      format(1x,i4,1x,i1,2(1x,f8.5),2(1x,f9.6))
          go to 1
          
900   continue
      stop
end program mean_turn_xsret_annc